package com.tangcco.lockwell.controller.student;

import com.tangcco.lockwell.base.RestResponse;
import com.tangcco.lockwell.domain.dto.StatisticalStudyReportParentDto;
import com.tangcco.lockwell.service.AnswerContentRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.temporal.WeekFields;

/**
 * 统计控制器
 *
 * @author yanxinping
 * @date 2025-01-10 10:52
 */
@RestController
@RequestMapping("/api/student/statistics")
public class StatisticsController {

    @Autowired
    private AnswerContentRecordService answerContentRecordService;

    @RequestMapping("/statisticalStudyReport")
    public RestResponse<StatisticalStudyReportParentDto> statisticalStudyReport(@RequestParam(value = "week", required = false) Integer week,
                                                                                @RequestParam(value = "userId", required = false) Integer userId) {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        if(week == null || week == 0 ) {
            // 获取当前日期
            // 使用默认的ISO周定义获取当前是一年中的第几周
            week = currentDate.get(WeekFields.ISO.weekOfYear());
        }
        StatisticalStudyReportParentDto statisticalStudyReportParentDto = answerContentRecordService.statisticalStudyReport(week,userId);
        statisticalStudyReportParentDto.setMaxWeek(currentDate.get(WeekFields.ISO.weekOfYear()));
        return RestResponse.ok(statisticalStudyReportParentDto);
    }
}

